package com.csea.app.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.csea.app.model.vo.user.PasswordUpdateReqVO;
import com.csea.app.model.vo.user.UserBaseInfoUpdateReqVO;
import com.csea.app.model.vo.user.UserInfoRspVO;
import com.csea.app.service.UserAccountService;
import com.csea.common.aspect.ApiOperationLog;
import com.csea.common.utils.Response;
import cn.dev33.satoken.annotation.SaCheckLogin;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app/user")
@Tag(name = "用户管理")
public class UserController {

    @Autowired
    private UserAccountService userAccountService;

    @GetMapping("/info")
    @SaCheckLogin
    @Operation(summary = "获取当前用户信息")
    @ApiOperationLog(description = "获取当前用户信息")
    public Response<UserInfoRspVO> getCurrentUserInfo() {
        return userAccountService.getCurrentUserInfo();
    }


    @PostMapping("/edit/baseInfo")
    @SaCheckLogin
    @Operation(summary = "更新用户基本信息")
    @ApiOperationLog(description = "更新用户基本信息")
    public Response<UserInfoRspVO> updateUserBaseInfo(@RequestBody @Validated UserBaseInfoUpdateReqVO reqVO) {
        return userAccountService.updateUserBaseInfo(reqVO);
    }

    @PostMapping("/edit/password")
    @SaCheckLogin
    @Operation(summary = "更新用户密码")
    @ApiOperationLog(description = "更新用户密码")
    public Response<String> updatePassword(@RequestBody @Validated PasswordUpdateReqVO reqVO) {
        return userAccountService.updatePassword(reqVO);
    }
}